// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    imgUrls: [
      '../../img/1.jpg',
      '../../img/11.jpg',
      '../../img/111.jpg'
    ],
    songsList:[],
    songIdList:[],
    albumImgList:[],
    name:'',
    newsdata1:[
      {"newsImg":'../../img/news.jpg',
      "newsText":'面对军训，是一次挑战,是一次锻炼意志的机会。',
      "newsTimeText":'2021/8/20',
      "newsPlaceText":'地点：A6-103'
    },
      {"newsImg":'../../img/news1.jpg',
      "newsText":'炫酷轮滑社团来袭保持高超  表演技巧让你尖叫不停',
      "newsTimeText":'2021/8/16',
      "newsPlaceText":'地点：A5-110'
    },
      {"newsImg":'../../img/news2.jpg',
      "newsText":'培养具有创业基本素质和开创型个性的人才为目标.',
      "newsTimeText":'2021/8/13',
      "newsPlaceText":'地点：A6-120'
    }
    ],
    newsdata2:[
      {"newsImg":'../../img/news3.jpg',
      "newsText":'菜鸟驿站“变了”：送货上门或免费保管。',
      "newsTimeText":'2021/8/20',
      "newsPlaceText":'地点：D9'
    },
      {"newsImg":'../../img/news4.jpg',
      "newsText":'好消息 新校区每层楼都装有24小时自习室。',
      "newsTimeText":'2021/8/16',
      "newsPlaceText":'地点：A5-110'
    },
      {"newsImg":'../../img/news5.jpg',
      "newsText":'数字时代来了 现在哪个年轻人还不知道PS。',
      "newsTimeText":'2021/8/13',
      "newsPlaceText":'地点：A6-120'
    }
    ]
  },
  onLoad() {
    var name = "张杰"
    if(name){
      wx.showToast({
        title: '加载中',
        icon: 'loading',
        duration: 500
      })
      wx.request({
        url: 'https://music.163.com/api/search/get?s=' + name + '&type=1&limit=4',
        success: (res)=>{
          var list1 = []
          for(var i=0; i < res.data.result.songs.length; i++){
            var songId = res.data.result.songs[i].id
            list1.push(songId)
          }
            this.setData({
              songsList: res.data.result.songs,
              songIdList: list1
            })
        },
        fail: (res)=>{
          console.log(res)
        }
      })
    }
  },
  onReachBottom: function () {
    if(this.data.newsdata1.length<6){
      wx.showToast({
      title: '加载中',
      icon:"loading",
      duration:1000
    })
    this.setData({
      newsdata1:this.data.newsdata1.concat(this.data.newsdata2)
    })
    }else{
      wx.showToast({
        title: '暂时没有新消息',
        icon:"end",
        duration:1000
      })
    }
  },
  tonews(){
    wx.navigateTo({
      url: '../news/news',
    })
  }, 
  weather() {
    wx.navigateTo({
      url: '../weather/weather',
    })
  },
  map() {
    wx.navigateTo({
      url: '../map/map',
    })
  },
  today(){
    wx.navigateTo({
      url: '../day/day',
    })
  },
  toHotMusic(){
    wx.navigateTo({
      url: '../hotMusic/hotMusic',
    })
  },
  toPlay(event){
    var id = event.currentTarget.dataset.musicid
    wx.navigateTo({
      url: '../hotMusic/hotMusic?id=' + id + '&idList=' + this.data.songIdList,
    })
   
  },
})
